import 'package:flutter/material.dart';
import 'dart:math';


class MyColorfulApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Color containerColor = getcolor();
  Color textColor = getcolor();

  void changeColor() {
    setState(() {
      containerColor = getcolor();
      textColor = getcolor();
      print("containerColor "+containerColor.toString());
      print("textColor "+textColor.toString());
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Color Changing Container'),
      ),
      body: GestureDetector(
        onTap: () {
          changeColor();
        },
        child: Container(
          color: Colors.grey, // 背景颜色
          child: Center(
            child: Flex(
              direction: Axis.vertical,
              children: [
                Expanded(
                  child: Container(
                    color: containerColor,
                    child: Center(
                      child: Text(
                        "李若辰",
                        style: TextStyle(
                          color: textColor,
                          fontSize: 40.0,
                          fontWeight: FontWeight.bold,
                          fontStyle: FontStyle.italic,
                          letterSpacing: 2.0,
                          wordSpacing: 5.0,
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Color getcolor() {
  Random random = Random();
  return Color.fromARGB(
    255,
    random.nextInt(256),
    random.nextInt(256),
    random.nextInt(256),
  );
}
